package org.tgcloud.group.core.session;

import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;
import java.util.List;
import java.util.UUID;

/**
 * Created by cloudLiu on 2015/8/6.
 */
public class SimpleSession implements Session,Serializable {

    private transient static final Logger logger = LoggerFactory.getLogger(SimpleSession.class);

    private static final long serialVersionUID = -7125642615178165650L;

    protected static final long MILLIS_PER_SECOND = 1000;
    protected static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND;
    protected static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
    protected static final long MILLIS_PRE_DAY = 30 * MILLIS_PER_HOUR;
//  默认timeout时间
    public static final long DEFAULT_GLOBAL_SESSION_TIMEOUT = 30 * MILLIS_PER_MINUTE;

    private Serializable id;
    private int userId;
    private short userType;
    private String devToken;
    private String comId; // 角色id集合
    private List<String> powers;

    public SimpleSession()
    {
        this(null);
    }
    public SimpleSession(String token)
    {
        this(token,null);
    }

    public SimpleSession(String token, String dev_token)
    {
        this.id = Strings.isNullOrEmpty(token)? UUID.randomUUID().toString():token;
        this.devToken = dev_token;
    }

    public List<String> getPowers() {
        return powers;
    }

    public void setPowers(List<String> powers) {
        this.powers = powers;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Override
    public short getUserType() {
        return userType;
    }

    public void setUserType(short userType) {
        this.userType = userType;
    }

    @Override
    public Serializable getId() {
        return this.id;
    }

    public void setId(Serializable id) {
        this.id = id;
    }

    public String getDevToken() {
        return devToken;
    }

    public void setDevToken(String devToken) {
        this.devToken = devToken;
    }

    public String getComId() {
        return comId;
    }

    public void setComId(String comId) {
        this.comId = comId;
    }
}
